package com.qfedu.tantu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qfedu.tantu.dao.HousInfoDao;
import com.qfedu.tantu.entity.Housinfo;
import com.qfedu.tantu.service.intf.HousInfoService;
import com.qfedu.tantu.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author: 赵金帅
 * @Date: 2022/07/02/1:32
 */
@Service
public class HousInfoServiceImpl implements HousInfoService {
    @Resource
    private HousInfoDao dao;
    @Override
    public R selectAllByName(String housname) {
        QueryWrapper<Housinfo> wrapper=new QueryWrapper<>();
        if(housname!=null && housname.length()>0){
            //模糊查询
            wrapper.like("housname","%"+housname+"%");
        }
        return R.ok(dao.selectList(wrapper));
    }

    @Override
    public R selectByLocation(String location) {
        QueryWrapper<Housinfo> wrapper=new QueryWrapper<>();
        if(location!=null && location.length()>0){
            //模糊查询
            wrapper.like("location","%"+location+"%");
        }
        return R.ok(dao.selectList(wrapper));
    }

    @Override
    public R selectAll(Integer id) {
        if (id>0){
            Housinfo housinfo = dao.selectOne(new QueryWrapper<Housinfo>().eq("id", id));
            if (housinfo!=null){
                return R.ok(housinfo);
            }
        }
        return R.fail("参数非法");
    }

    @Override
    public R select() {
        List<Housinfo> housinfos = dao.selectList(new QueryWrapper<Housinfo>().orderByAsc("id"));
        if (housinfos!=null){
            return R.ok(housinfos);
        }
        return R.fail();
    }
}
